#!/usr/bin/perl

###########################################
#Author :  DebugProject _Brebion
#Created : 02/03/07
#Modified : 05/03/07
#Script : Scipt to get back files
###########################################

#Verification de la ligne de commande
if(scalar(@ARGV) !=3){die "[usage : <pathToStored> <pathWhereFind> <fileConfig> ]"}	

$pathToStored = $ARGV[0];
$pathWhereFind = $ARGV[1];
$fileConfig = $ARGV[2];

#vérification que le fichier d'entree existe bien
if(!(-e $fileConfig)){die "[The file input doesn't exist]"}


#Ouverture des handles
open(INPUT,"<$fileConfig") || die "[Open file $fileConfig impossible]";

#creation table of stations
@tabStation;

while($ligne=<INPUT>){
	$ligne =~ /(.*);/;
	$tabStation[$#tabStation + 1] = $1;
}

$nbElement=scalar(@tabStation);

for($i=0;$i<$nbElement;$i++){
	$host = "host";
	$i = $i+1;
	$name = $pathWhereFind.$host.$i."/log*.xml";
	$i = $i-1;
	$hote = `scp -r @tabStation[$i]:$name $pathToStored`;	
	$eff = `ssh @tabStation[$i] "rm -r -f $pathWhereFind/*"`;
#	$kill = `ssh @tabStation[$i] "killall java"`; voir si c utile
}


close INPUT
